package com.applet.message.controller;

import java.util.List;
import java.util.Map;
import javax.servlet.http.HttpServletResponse;

import com.applet.message.domain.dto.MessageDto;
import com.applet.message.domain.vo.MessageVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.applet.common.annotation.Log;
import com.applet.common.core.controller.BaseController;
import com.applet.common.core.domain.AjaxResult;
import com.applet.common.enums.BusinessType;
import com.applet.message.domain.Message;
import com.applet.message.service.IMessageService;
import com.applet.common.utils.poi.ExcelUtil;
import com.applet.common.core.page.TableDataInfo;

/**
 * 消息处理Controller
 *
 * @author hhy
 * @date 2024-09-06
 */
@Api(tags = "消息处理")
@RestController
@RequestMapping("/message/message")
public class MessageController extends BaseController {
    @Autowired
    private IMessageService messageService;

    /**
     * 查询消息列表
     */
    @ApiOperation(value = "查询消息列表")
//    @PreAuthorize("@ss.hasPermi('message:message:list')")
    @GetMapping("/list")
    public TableDataInfo list(MessageVo messageVo) {
        startPage();
        List<MessageDto> list = messageService.selectMessageList(messageVo);
        return getDataTable(list);
    }

    @GetMapping("/user/list")
    public AjaxResult userList(MessageVo messageVo) {
        startPage();
        Map<String, List<MessageDto>> map = messageService.selectMessageListByUser(messageVo);
        return success(map);
    }

    /**
     * 导出消息处理列表
     */
//    @PreAuthorize("@ss.hasPermi('message:message:export')")
    @Log(title = "消息处理", businessType = BusinessType.EXPORT)
    @ApiOperation(value = "导出消息列表")
    @PostMapping("/export")
    public void export(HttpServletResponse response, MessageVo messageVo) {
        List<MessageDto> list = messageService.selectMessageList(messageVo);
        ExcelUtil<MessageDto> util = new ExcelUtil<>(MessageDto.class);
        util.exportExcel(response, list, "消息处理数据");
    }

    /**
     * 获取消息处理详细信息
     */
//    @PreAuthorize("@ss.hasPermi('message:message:query')")
    @ApiOperation(value = "获取消息详细信息")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(messageService.selectMessageById(id));
    }

    /**
     * 新增消息处理
     */
//    @PreAuthorize("@ss.hasPermi('message:message:add')")
    @Log(title = "消息处理", businessType = BusinessType.INSERT)
    @ApiOperation(value = "新增消息")
    @PostMapping
    public AjaxResult add(@RequestBody Message message) {
        return toAjax(messageService.insertMessage(message));
    }

    /**
     * 修改消息处理
     */
//    @PreAuthorize("@ss.hasPermi('message:message:edit')")
    @Log(title = "消息处理", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "修改消息")
    @PutMapping
    public AjaxResult edit(@RequestBody Message message) {
        return toAjax(messageService.updateMessage(message));
    }

    @Log(title = "消息处理", businessType = BusinessType.UPDATE)
    @ApiOperation(value = "批量修改消息")
    @PutMapping("/status/{ids}")
    public AjaxResult batchEdit(@PathVariable Long[] ids) {
        return toAjax(messageService.batchUpdateMessageStatus(ids));
    }

    /**
     * 删除消息处理
     */
//    @PreAuthorize("@ss.hasPermi('message:message:remove')")
    @Log(title = "消息处理", businessType = BusinessType.DELETE)
    @ApiOperation(value = "删除消息")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(messageService.deleteMessageByIds(ids));
    }
}
